home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.3 KB | 240 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWCmd.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWCMD_H
- #define FWCMD_H
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- // for ODName
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <Undo.xh>
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //==============================================================================
- // Forward Declarations
- //==============================================================================
-
- class FW_CLASS_ATTR FW_CPart;
- class FW_CLASS_ATTR FW_CFrame;
- class FW_CLASS_ATTR FW_CSelection;
- class FW_CLASS_ATTR FW_CString;
- class FW_CLASS_ATTR ODUndo;
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- #define FW_kCanUndo TRUE
- #define FW_kCantUndo FALSE
-
- //==============================================================================
- // class FW_CCommand
- //==============================================================================
-
- class FW_CLASS_ATTR FW_CCommand FW_AUTO_DESTRUCT_OBJECT
- {
- public:
- FW_DECLARE_CLASS
-
- public:
-
- //------------------------------------------------------------------------
- // --- Initialization/Destruction ---
-
- FW_CCommand(Environment* ev,
- ODCommandID id,
- FW_CFrame* frame,
- FW_Boolean canUndo);
- virtual ~ FW_CCommand();
-
- //------------------------------------------------------------------------
- // --- Command API ---
-
- void PerformCommand(Environment* ev);
- // Perform the command by calling DoIt,
- // and take care of OpenDoc Undo/Redo paperwork if necessary
-
- virtual void DoIt(Environment* ev) = 0;
- // Must be overridden by all commands
-
- //------------------------------------------------------------------------
- // --- API for Undo-able Commands ---
-
- virtual void UndoIt(Environment* ev);
- virtual void RedoIt(Environment* ev);
- // Undo-able commands must override
- // Default does nothing
-
- virtual void CommitDone(Environment* ev);
- // Called just before the command is deleted.
- // doneState values are kODDone or kODRedone (ODTypes.h)
- // Default calls FreeUndoState
-
- virtual void CommitUndone(Environment* ev);
- // Called just before the command is deleted.
- // doneState value is kODUndone (ODTypes.h)
- // Default calls FreeRedoState
-
- virtual void SaveUndoState(Environment* ev);
- virtual void SaveRedoState(Environment* ev);
- // Save state of data for later undo and redo
- // Default does nothing
-
- virtual void FreeUndoState(Environment* ev);
- virtual void FreeRedoState(Environment* ev);
- // Free data saved for undo and redo
- // Default does nothing
-
- //------------------------------------------------------------------------
- // --- New API ---
-
- ODActionType GetActionType(Environment* ev) const;
- FW_Boolean GetCanUndo(Environment* ev) const;
- FW_Boolean GetCausesChange(Environment* ev) const;
- ODCommandID GetCommandID(Environment* ev) const;
-
- FW_Boolean HasAddedAction(Environment* ev) const;
-
- void SetActionType(Environment* ev, ODActionType actionType);
- void SetCausesChange(Environment* ev, FW_Boolean causesChange);
-
- protected:
- void SetMenuStrings(Environment* ev,
- const FW_CString& undoString,
- const FW_CString& redoString);
- void SetMenuStrings(Environment* ev,
- char* undoChars,
- char* redoChars);
- // Call one of these to set up menu strings for Undo and Redo
-
-
- void AddAction(Environment* ev,
- ODActionType actionType,
- octet* dataPtr,
- unsigned long dataSize,
- ODName* undoActionLabel,
- ODName* redoActionLabel);
- // Call ODUndo::AddActionToHistory; used for transactions
-
- FW_Boolean IsOKtoEdit(Environment* ev);
- // Checks whether it's OK to change this part and frame
-
- private:
- void PrivDisposeUndoStrings();
-
- //------------------------------------------------------------------------
- // --- Data Members ---
-
- protected:
- ODCommandID fCommandID;
- FW_Boolean fCanUndo; // Default = TRUE
- FW_Boolean fCausesChange; // Default = TRUE
- ODActionType fActionType; // Default = kODSingleAction
-
- FW_CPart* fPart;
- FW_CFrame* fFrame;
- FW_CSelection* fSelection;
-
- ODName* fUndoString; // string for Undo menu item
- ODName* fRedoString; // string for Redo menu item
-
- private:
- ODUndo* fUndo;
- FW_Boolean fHasAddedAction; // TRUE if this command has called AddAction
-
- // Don't allow commands to be copied or returned from functions
- FW_CCommand(const FW_CCommand& command); // Copy constructor
- FW_CCommand& operator=(const FW_CCommand& command); // Assignment operator
- };
-
- //========================================================================================
- // FW_CCommand Inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetActionType
- //----------------------------------------------------------------------------------------
- inline ODActionType FW_CCommand::GetActionType(Environment* ev) const
- {
- return fActionType;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetCanUndo
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CCommand::GetCanUndo(Environment* ev) const
- {
- return fCanUndo;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetCausesChange
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CCommand::GetCausesChange(Environment* ev) const
- {
- return fCausesChange;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::GetCommandID
- //----------------------------------------------------------------------------------------
- inline ODCommandID FW_CCommand::GetCommandID(Environment* ev) const
- {
- return fCommandID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::HasAddedAction
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CCommand::HasAddedAction(Environment* ev) const
- {
- return fHasAddedAction;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetActionType
- //----------------------------------------------------------------------------------------
- inline void FW_CCommand::SetActionType(Environment* ev, ODActionType actionType)
- {
- fActionType = actionType;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CCommand::SetCausesChange
- //----------------------------------------------------------------------------------------
- inline void FW_CCommand::SetCausesChange(Environment* ev, FW_Boolean causesChange)
- {
- fCausesChange = causesChange;
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-